<?php

namespace App\Models\Note;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;

class Doc extends BaseModel
{
    use SoftDeletes;

    protected $table = 'note_doc';

    protected $fillable = [
        'title',
        'tags',
        'url',
        'status',
    ];

    protected $appends = ['status_tr'];

    public static $StatusEnum = [0 => "草稿", 1 => "发布"];

    public function getTagsAttribute($value)
    {
        return $value ? explode(',', $value) : [];
    }

    public function setTagsAttribute($value)
    {
        $this->attributes['tags'] = implode(',', $value);
    }

    public function getStatusTrAttribute()
    {
        return self::$StatusEnum[$this->status] ?? $this->status;
    }
}
